package com.mybatis.controller;

import com.mybatis.entity.User;
import com.mybatis.service.UserService;
import jnr.ffi.annotations.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liuxiaoding
 * @Date 2019/11/8
 **/
@RestController
@RequestMapping(value = "user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "selectAll")
    public List<User> selectAll(){
        return userService.selectAll();
    }

    @RequestMapping(value = "insert")
    public String insert(User user){
        int result=userService.insert(user);
        return "主键："+user.getId()+",返回："+result;
    }

    @RequestMapping(value = "delete")
    public String insert(Integer id){
        return userService.delete(id)==1?"suc":"fail";
    }

    @RequestMapping(value = "update")
    public String update(Integer userId,String email){
        User user=new User();
        user.setId(userId);
        user.setEmail(email);
        return userService.update(user)==1?"suc":"fail";
    }
    @RequestMapping(value = "selectUserInfo")
    public User selectUserInfo(Integer userId){
        return userService.selectUserInfo(userId);
    }

    @RequestMapping(value = "selectUserShipAddress")
    public User selectUserShipAddress(Integer userId){
        return userService.selectUserShipAddress(userId);
    }

    @RequestMapping(value="testOverIn")
    public List<User> test(@RequestBody List<Integer> userIds){
        return userService.selectByUserIds(userIds);
    }
}
